package businesslogic.user;

import java.rmi.RemoteException;

import javax.swing.table.DefaultTableModel;

import Enum.Faculty;
import Enum.Gender;
import Enum.Hometown;
import Enum.UserRole;
import po.userpo.Birthday;
import po.userpo.UserID;
import po.userpo.UserPO;
import useDatabase.java.getTable;

public class GetUserByID {
	  UserID id;
     
	  public GetUserByID(UserID id){
    	  this.id=id;
      }
      
	  public UserPO getUser(){
		  getTable table=new getTable();
		  UserPO po = null;
		  DefaultTableModel model;
		 try {
			 model= table.getTable("user", "*", "userID='"+id.getID()+"'");
		     po=new UserPO(new UserID(model.getValueAt(0, 0).toString()),
					    model.getValueAt(0, 5).toString(), null, Integer.parseInt( model.getValueAt(0, 4).toString()),
					    UserRole.valueOf( model.getValueAt(0, 2).toString()), 
					    Gender.valueOf( model.getValueAt(0, 6).toString()),
					    Faculty.valueOf( model.getValueAt(0, 7).toString())	, 
					    Hometown.valueOf( model.getValueAt(0, 8).toString()), 
					    new Birthday(Integer.parseInt(model.getValueAt(0, 3).toString().split("-")[0]),
								Integer.parseInt(model.getValueAt(0, 3).toString().split("-")[1]),
								Integer.parseInt(model.getValueAt(0, 3).toString().split("-")[2])), 
						 model.getValueAt(0, 9).toString());
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			 return po;
		  
	  }
      
}
